<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我要提问</title>
    <script type="text/javascript" src="js/jquery-3.4.1.js"></script>
</head>
<body>
<h1 style="margin:20px auto;  display:table;">我要提问</h1>
<div style="margin:20px auto;  display:table;"><a href="index.html">返回首页</a></div>
<div style="margin:20px auto;  display:table;">
    <form id="form" method="get" action="">
        <p>问题：<input type="text" id="title" name="title"></p>
        <p>问题描述：<textarea rows="3" cols="20" id="detailDesc" name="detailDesc"></textarea></p>
        <!--        <button id="submit">保存问题</button>-->
        <input type="submit" id="submit" value="提交问题">
    </form>
</div>
</body>
<script type="text/javascript">
    $(function () {
        $("#submit").click(function () {
            var title = $("#title").val();
            var detailDesc = $("#detailDesc").val();
            if (title.trim() == "") {
                alert("必须填写问题");
                return false;
            }
            $.post("addQuestion", {"title": title, "detailDesc": detailDesc}, function (p) {
                console.log(JSON.stringify(p));
                if (p.code == 0) {
                    alert(p.msg);
                    $(location).prop("href", "index.html");
                    return false;
                }
                alert(p.msg);
            })
            return false;
        });

    });
</script>
</html>